package com.lbs.jiepiaisi.parser;

import com.lbs.jiepiaisi.bean.PhotoImgBean;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * 时间：2018/1/11 17:29
 * 作用：
 */

public class PhotoImageParser {

    //解析方法
    public static PhotoImgBean parser(String jsonString){
        PhotoImgBean photoImgBean = new PhotoImgBean();
        try{
            JSONObject jsonObject = new JSONObject(jsonString);
            int status = jsonObject.getInt("status");
//            photoImgBean.setStatus(status);
            if(status == 0){
//                PhotoImgBean.Result.Installer installer = new PhotoImgBean.Result.Installer();
                JSONArray jsonArray = jsonObject.getJSONArray("result");
//                installer.setInstaller(jsonArray.getJSONObject(0).getString("installer"));
//                installer.setInstallerPhone(jsonArray.getJSONObject(0).getString("installerPhone"));
//                installer.setInstallerPosition(jsonArray.getJSONObject(0).getString("installerPosition"));
//                PhotoImgBean.Result result = new PhotoImgBean.Result();
//                result.setInstaller(installer);
//                List<PhotoImgBean.Result.Image> images = new ArrayList<>();
                JSONArray jsonArrayImage = jsonObject.getJSONArray("result").getJSONArray(1);
                for(int i = 0; i < jsonArrayImage.length();i++){
                    JSONObject imgObject = jsonArrayImage.getJSONObject(i);
//                    PhotoImgBean.Result.Image img = new PhotoImgBean.Result.Image();
//                    img.setFileId(imgObject.getInt("fileId"));
//                    img.setFileName(imgObject.getString("fileName"));
//                    img.setFilePath(imgObject.getString("filePath"));
//                    img.setFilePid(imgObject.getString("filePid"));
//                    img.setFileSuffix(imgObject.getString("fileSuffix"));
//                    img.setFileTable(imgObject.getString("fileTable"));
//                    img.setId(imgObject.getInt("id"));
//                    img.setType(imgObject.getInt("type"));
//                    img.setUploadTime(imgObject.getString("uploadTime"));
//                    img.setVersion(imgObject.getInt("version"));
//                    images.add(img);
                }
//                result.setImages(images);
//                photoImgBean.setResult(result);
            }

        }catch (Exception e){
            e.printStackTrace();
        }
        return photoImgBean;
    }
}
